package dom;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class CreateXMLFile {
	public static void main(String[] args) throws IOException {
		Element root = new Element("books");
		Document document = new Document();
		document.setRootElement(root);
		for(int i=0; i<10; i++){
			Element bookElement = new Element("book");
			bookElement.setAttribute("id", "c"+i);
			Element nameElement = new Element("name");
			nameElement.setText("book"+i);
			Element priceElement = new Element("price");
			priceElement.setText(i+3+"");
			
			bookElement.addContent(nameElement);
			bookElement.addContent(priceElement);
			root.addContent(bookElement);
			
		}
		Writer writer = new FileWriter("book.xml");
		XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
		outputter.output(document, writer);
		writer.close();
	}

}
